<?php 
$zone = $_POST['name'];
$desc = mysql_real_escape_string($_POST['desc']);
$authorised = $_POST['authorised'];
	
if(isset($_POST['savejob']))
{
	
	if($_GET['m']!=edit)
	{
				
		mysql_query("INSERT INTO job_category (`category`, `desc`, `active_status`, `created_datetime`) VALUES ('$zone','$desc','$authorised',now())");	
		//header("location: index.php?tc=addcat&_s=1");
		echo "<script>window.location='index.php?tc=add_jobcat&_s=1'</script>";
	}
	
}
if(isset($_POST['updatejob']))

{


mysql_query("UPDATE job_category  SET `category` = '$zone',`desc` ='$desc',`active_status` ='$authorised',
			`modified_datetime`=now() where id='".$_POST['hid']."'")
or 
die(mysql_error());

	
	echo "<script>window.location='index.php?tc=job_category&_s=1'</script>";
	
}
?>

<script type="text/javascript">
function validate()
{
	if(document.up.name.value=="")
	{
		alert("Category Name Missing.");	
		document.up.name.focus();
		return false;
	}
}
</script>
<?php if($_REQUEST['_s'] == 1){ ?>
    <div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Successfully saved.</div>
<?php } ?>
<?php if($_REQUEST['_e'] == 1){ ?>
    <div class="sucmsg"><img src="images/error.png" align="absmiddle" />&nbsp;</div>
<?php } ?>
<?php 
$ssql="select * from job_category where id='".$_GET['_d']. "'";
$ssql=mysql_query($ssql);
$row =mysql_fetch_array($ssql);
if($row['active_status']=='1')
{
	
$chkact = 'checked="checked"';
}
if($row['active_status']=='0')
{
	
$chkdec = 'checked="checked"';
}
?>
<form name="up" action="#" method="post" onSubmit="return validate()">
<table width="99%" align="center" border="0"  class="list" cellpadding="5">
<input type="hidden" name="hid" value="<?php echo  $row['id'];?>" />
<thead>
<tr>
	<td colspan="2" align="left">
        <div style="float:left" class="righthead">Job Category</div>
        <div style="float:right"><a href="index.php?tc=job_category" class="back">View Category</a></div>
    </td>
</tr>
</thead>
<tr>
	<td align="right" width="150">Category Name</td>
    <td align="left"><input type="text" name="name" style="width:200px;" value="<?php echo  $row['category'];?>"  /></td>
</tr>
<tr>
	<td align="right" width="250">Category Description</td>
    <td align="left">
   <textarea name="desc" style="width:300px; height:150px;"><?php echo  stripslashes($row['desc']);?></textarea></td>
   
</tr>
<tr>
  <td align="right" width="150">Status :</td>
  <td align="left">
  <input name="authorised" type="radio"  value="1" checked="checked" <?php echo $chkact;?> />&nbsp;Active&nbsp;&nbsp;
  <input  name="authorised" type="radio" value="0" <?php echo $chkdec;?> />&nbsp;Deactive</td>
</tr>

<tr>
	<td colspan="2" style="padding-left:155px;">
    	<?php if($_GET['m']!=edit){?>
        <input type="submit" value="Save" name="savejob" >&nbsp;&nbsp;
        <?php }
        else
		{
         ?>
          <input type="submit" value="Update" name="updatejob" >
         <?php 
		
		}
         ?>
    </td>
</tr>        
</table>   
</form> 
